https://leetcode.cn/problems/course-schedule-ii/
class Solution {
public:
    vector<int> findOrder(int n, vector<vector<int>>& p) {       
        //建表
        unordered_map<int,vector<int>> edges;
        vector<int> in(n);
        for(auto e:p)
        {
            //b->a
            int a=e[0],b=e[1];
            edges[b].push_back(a);
            in[a]++;
        }

        queue<int> q;
        //入队列
        for(int i=0;i<n;i++)
        {
            if(!in[i])
                q.push(i);
            cout<<q.front()<<" ";
        }

        vector<int> ret;
        while(!q.empty())
        {
            int t=q.front();q.pop();
            ret.push_back(t);
            for(auto e:edges[t])
            {
                --in[e];
                if(!in[e])
                    q.push(e);
            }
        }
        if(ret.size()==n)
            return ret;
        
        return {};
    }
};